WITH Ada.Text_IO;
WITH Ada.Strings.Unbounded;
WITH GNAT.String_Split;
WITH Ada.Strings.Unbounded.Text_IO;
WITH Ada.Strings.Maps;
WITH Xml_Readers;
--
--
--
PROCEDURE Test_Xml_Readers IS

  PACKAGE Dyn_Str RENAMES Ada.Strings.Unbounded;
  PACKAGE Integer_IO IS NEW Ada.Text_IO.Integer_Io (Integer);

  File_Path    : String := "../data/rdp1.xml";
  Root_Section : String := "petrinet";
  Handler      : Xml_Readers.Handler;
  Value         : Dyn_Str.Unbounded_String ;
  Value_List    : GNAT.String_Split.Slice_Set;
BEGIN
  Xml_Readers.Load (Handler, File_Path, Root_Section);



  WHILE Xml_Readers.Has_Next_Element (Handler) LOOP

    Xml_Readers.Next_Element (Handler);
    --PLACES
    IF Xml_Readers.Current_Element(Handler)="place" THEN
      Xml_Readers.Next_Element (Handler);

      Value :=Dyn_Str.To_Unbounded_String(Xml_Readers.Current_Element (Handler));

      GNAT.String_Split.Create (Value_List, Dyn_Str.To_String (Value) , Ada.Strings.Maps.To_Set (":"), Mode => GNAT.String_Split.Multiple);
      Ada.Text_IO.Put_Line ("new Place : " & GNAT.String_Split.Slice (Value_List, 1));
      Ada.Text_IO.Put ("Mark init : " );
      Integer_IO.Put(Integer'Value (GNAT.String_Split.Slice (Value_List, 2)));
      Ada.Text_IO.New_Line;
      --TRANSITIONS
    ELSIF Xml_Readers.Current_Element (Handler) =  "transition" THEN
      Xml_Readers.Next_Element (Handler);
      Ada.Text_IO.Put_Line ("New transition : " & Xml_Readers.Current_Element (Handler));
      --ARROW
    ELSIF Xml_Readers.Current_Element(Handler) ="arrow" THEN
      Xml_Readers.Next_Element (Handler);

      Value := Dyn_Str.To_Unbounded_String(Xml_Readers.Current_Element (Handler));
      Value := Dyn_Str.Trim (Value, Ada.Strings.Both);

      GNAT.String_Split.Create (Value_List, Dyn_Str.To_String (Value) , Ada.Strings.Maps.To_Set (":" & " "), Mode => GNAT.String_Split.Multiple);
      Ada.Text_IO.Put ("New arrow : " & GNAT.String_Split.Slice (Value_List, 1));
      Ada.Text_IO.Put (" to : " & GNAT.String_Split.Slice (Value_List, 2));

      Ada.Text_IO.New_Line;
    END IF;

    --EXIT WHEN NOT Xml_Readers.Has_Next_Element (Handler);
  END LOOP;
  Xml_Readers.Close (Handler);

END Test_Xml_Readers;
